package com.github.eclipseace.mybatis.util;

import java.util.Collection;

/**
 * @author eclipseAce
 */
public final class Assert {
	private Assert() {
	}

	public static void isTrue(boolean expression, String message) {
		if (!expression) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void isNull(Object object, String message) {
		if (object != null) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void isNotNull(Object object, String message) {
		if (object == null) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void isNotEmpty(CharSequence cs, String message) {
		if (cs == null || cs.length() < 1) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void isNotEmpty(Collection<?> collection, String message) {
		if (collection == null || collection.size() < 1) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void isInstanceOf(Object object, Class<?> type, String message) {
		isNotNull(type, "type to check is null");
		if (object == null || !type.isInstance(object)) {
			throw new IllegalArgumentException(message);
		}
	}

	public static void isInterface(Class<?> type, String message) {
		if (type == null || !type.isInterface()) {
			throw new IllegalArgumentException(message);
		}
	}
}
